package com.neusoft.news.utils;

//import org.yaml.snakeyaml.Yaml;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
//import java.util.Map;

/**
 * JDBC 工具类
 *
 * @author wh
 * @ClassName: JDBCUtils
 * @Description: JDBC
 * @date 2021年5月22日
 * @since JDK 1.8
 */
public class JDBCUtils {
    private static Connection conn = null;

    private JDBCUtils() {
    }

    /**
     * 获取连接
     *
     * @return 连接对象
     * @throws ClassNotFoundException JDBC 加载问题
     * @throws SQLException           数据库连接问题
     * @Title: getConnection
     * @Description: 获取连接
     */
    public static Connection getConnection() throws ClassNotFoundException, SQLException {
//        if (conn == null) {
//            synchronized (JDBCUtils.class) {
//                if (conn == null) {
//        Yaml yaml = new Yaml();
//        Map<String, Map<String, Object>> load = yaml.load(JDBCUtils.class.getClassLoader()
//                .getResourceAsStream("AppConfig.yml")
//        );
//        Map<String, Object> database = load.get("database");
//
//        Class.forName((String) database.get("classname"));
//
//        String url = (String) database.get("url");
//        String username = (String) database.get("username");
//        String pwd = (String) database.get("password");

        Class.forName("oracle.jdbc.OracleDriver");

        String url = "jdbc:oracle:thin:@localhost:1521:XE";
        String username = "SYSTEM";
        String pwd = "whb.1125";


        conn = DriverManager.getConnection(url, username, pwd);
//                }
//            }
//        }
        return conn;
    }

    /**
     * 销毁方法
     *
     * @throws SQLException 关闭问题
     * @Title: destroy
     * @Description: 关闭连接
     */
    public static void destroy() throws SQLException {
        if (conn != null) {
            conn.close();
        }
    }


}
